<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class BaseController extends CController
{
    public $layout;
    public $baseUrl;

    public function init()
    {
        $this->layout = '/layouts/main';
        $this->baseUrl = Yii::app()->getBaseUrl(true);
    }

    public function render($view, $data = null, $js = null, $css = null, $return = false)
    {
        // default script
        AssetUtility::addJs('libs/jquery-1.10.2.min.js');
        AssetUtility::addJs('libs/highcharts-3.0.6.js');

        // layout
        AssetUtility::addCss($this->layout.'.css');
        AssetUtility::addJs($this->layout.'.js');

        // autoload
        $controller = StringUtility::toUnderscore(Yii::app()->controller->id);
        AssetUtility::addCss('views/'.$controller.'/'.$view.'.css');
        AssetUtility::addJs('views/'.$controller.'/'.$view.'.js');

        // js
        if(is_array($js))
        {
            foreach($js as $file)
            {
                AssetUtility::addJs($file);
            }
        }

        // css
        if(is_array($css))
        {
            foreach($css as $file)
            {
                AssetUtility::addCss($file);
            }
        }

        return parent::render($view, $data, $return);
    }
}
